package com.wlyuan.open.assembler;

import com.wlyuan.core.named.CargoType;
import org.apache.commons.lang3.StringUtils;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;

/**
 * @author 订单转化类
 */
public class MappingOrder {

    public LocalDateTime parseTime(String time){
        if(StringUtils.isNotBlank(time)) {
            if(time.length()==16) {
                return LocalDateTime.parse(time, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"));
            }else{
                return LocalDateTime.parse(time.replace("T"," "), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
            }
        }
        return null;
    }

    public Integer cargoTypes(List<Integer> cargoTypes){
        //如果勾选了危险物品，则以危险物品为主，其次以温控
        if(cargoTypes!=null && cargoTypes.contains(CargoType.DANGER.getValue())){
            return CargoType.DANGER.getValue();
        }else if(cargoTypes!=null && cargoTypes.contains(CargoType.TEMPERATURE.getValue())){
            return CargoType.TEMPERATURE.getValue();
        }else{
            return CargoType.NORMAL.getValue();
        }
    }


}
